<?php

namespace Home\Controller;

/**
 * 资讯
 */
class NewsController extends CommonController {
    /**
     * 资讯首页
     * @return
     */
    public function index() {
        $news = M('News')->where("type='新闻资讯'")->order('id DESC')->select();

        $this->assign('news', $news);
        $this->display();
    }

    /**
     * 活动首页
     * @return
     */
    public function activity() {
        $news = M('News')->where("type='最新活动'")->order('id DESC')->select();

        $this->assign('news', $news);
        $this->display();
    }

    /**
     * 资讯内容
     * @return
     */
    public function show() {
        $news = D('News')->relation(true)
                         ->where("uuid='{$_GET['uuid']}'")
                         ->find();

        // 不存在则选取最新的一条
        if (empty($news)) {
            $news = D('News')->relation(true)->order('id DESC')->find();
        }

        $this->assign('news', $news);
        $this->display();
    }
}
